#ifndef HTTPHELPER_H
#define HTTPHELPER_H
#include<QNetworkAccessManager>
#include <QObject>
#include<QNetworkReply>
#include<memory>
#include<QObject>
#include<QVariantMap>
#include<QVector>
//http登录状态
enum REQUESTTYPE
{
    REGISTER=1,
    LOGIN,
    LOGINOUT,
    MEDIALIST,
    ADDMEDIA,
    EDITMEDIA,
    REMOVEMEDIA,
};
// 代码格式对其ctrl+a，ctrl+i

class HttpHelper : public QObject
{
    Q_OBJECT
public:
    static HttpHelper*instance();
    ~HttpHelper(){};
signals:
    //信号是没有返回值
    void sig_Operator(const REQUESTTYPE tybe,bool result);
    void sig_MediaInfo(const QVector<QVariantMap> mediainfo);
public slots:
    void slot_GetmediaInfo();
    void slot_Register(const QVariantMap& infomap);
    void slot_Login(const QVariantMap& infomap);
    void slot_LoginOut(const QVariantMap& infomap);
    void slot_AddmediaInfo(const QVariantMap& infomap);
    void slot_EditmediaInfo(const QVariantMap& infomap);
    void slot_RemovemediaInfo(const QVariantMap& infomap);
protected:
    void HandleReply(const QByteArray&data);
    void onReplyFinished(QNetworkReply*reply);
    void sendGetRequest(const QNetworkRequest&request);
    void sendRostRequest(QNetworkRequest&request,const QByteArray&data);
    void sendRequest(const REQUESTTYPE type ,bool isPost, const QByteArray data=QByteArray());

private:
    explicit HttpHelper(QObject*parent=nullptr);
    HttpHelper(const HttpHelper&)=delete ;
    HttpHelper& operator=(const HttpHelper&)=delete ;
private:
    QString token;
    static std::unique_ptr<HttpHelper>instance_ ;
    QNetworkAccessManager*networkManager=nullptr;
    std::map<REQUESTTYPE,QString>requestAdders;
signals:
};

#endif // HTTPHELPER_H
